/**
 * 关联产品分类
 * @author linfeng
 * @since 2019/08/19
 */
layui.define(['form', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;

    form.render(null, "zmn-categ-form");

    let ajaxIndex;
    // 提交
    form.on('submit(zmn-form-submit)', function (obj) {
        let url = "/showProduct/relation/batchAddRelation.action";
        //前台产品Id
        let param = {showProductId: json.showProductId};
        let showPlatArr = new Array();
        $("input:checkbox:checked").each((i, e) => {
            showPlatArr.push($(e).val())
        });
        param.productIds = showPlatArr;

        if (showPlatArr.length == 0) {
            layer.msg("关联数据为空，确定要删除所有的关联关系吗");
            return false;
        }

        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json",
            data: JSON.stringify(param),
            beforeSend: function () {
                ajaxIndex = layer.load(1, {
                    shade: [0.5, '#DBDBDB']
                });
            },
            success: function (json) {
                setTimeout(function () {
                    if (json.status == 200) {
                        layer.msg(json.message);
                        let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index);
                    } else {
                        layer.open({
                            type: 1,
                            content: json.message,
                            title: "提示",
                            area: [360 + 'px', 155 + 'px'],

                        })
                    }
                }, 1000);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        })

        layer.close(ajaxIndex);
        return false;
    });

    //点击取消
    $(document).on('click', '#cancel', function () {
        zmnLayUtil.closeThisTabs();
    });

    //对外暴露的接口
    exports('art_product_relation_edit', {});
});